package com.imooc.news_manager_project.common.enums;

import java.util.HashMap;
import java.util.Map;

public enum RoleEnum {
    ADMIN("管理员"), REPORTER("新闻记者"), USER("一般用户");
    private String text;

    RoleEnum(String text) {
        this.text = text;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public static boolean isContains(String code) {
        try {
            RoleEnum.valueOf(code);
            return true;
        } catch (IllegalArgumentException e) {
            return false;
        }
    }

    public static Map<String, String> getList() {
        HashMap<String, String> map = new HashMap<>();
        for (RoleEnum roleEnum : RoleEnum.values()) {
            map.put(roleEnum.name(), roleEnum.getText());
        }
        return map;
    }

}
